/**
 * Created by J on 2016/12/5.
 */
(function (angular) {
  var app=angular.module('goodsList.controllers',[
    'goodsList.service'
  ]);
  app.controller('goodsList.ctrl',function ($scope,$ionicHistory,goodsListFactory) {
    // 第一次加载数据
    refreshGoodsList();


    // 得到服务里的promise对象
    function refreshGoodsList() {
      var promise = goodsListFactory.getDataList();
      promise.then(function(data) {
        // 可能里还有一些其他操作
        $scope.obj_goodsListData = data;
        $scope.newData=data;
        // console.log(data);
      } );
    }

    // 刷新商品列表
    $scope.refreshGoodsList=function(){
      refreshGoodsList();
      // 广播，通知ionic去隐藏下拉刷新的标签
     $scope.$broadcast('scroll.refreshComplete');
    }

    // $scope.newData;
    // 上拉加载
    $scope.loadMoreGoodsList=function(){
      var newData= goodsListFactory.getMoreDataList();
      $scope.obj_goodsListData = $scope.obj_goodsListData.concat(newData);
      $scope.$broadcast('scroll.infiniteScrollComplete');
    }
    //点击返回
    $scope.goBack=function () {
      //通过历史纪录返回到原来页面
      console.log('test');
      $ionicHistory.goBack();
    }
  })
})(angular);
